//
//  ReservationTopView.m
//  Park
//
//  Created by 123456 on 2017/12/27.
//  Copyright © 2017年 YTYangK. All rights reserved.
//

#import "ReservationTopView.h"
#import "DateViewController.h"
#import "XLPhotoBrowser.h"
#import "MapViewController.h"
@implementation ReservationTopView
{
    UINavigationController *nav;
    UITabBarController *tabBarVc;

    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    tabBarVc = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    nav = (UINavigationController *)tabBarVc.selectedViewController;
    self.Image.userInteractionEnabled = YES;
    UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView)];
    PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
    PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
    self.Image.contentMode = UIViewContentModeScaleToFill;
    [self.Image addGestureRecognizer:PrivateLetterTap];
    
    self.Common = @"1";
    
    
    [self date];
    
}
//酒店详情
- (IBAction)details:(id)sender {
    MapViewController *M = [[MapViewController alloc]init];
    [nav pushViewController:M animated:YES];
    
}

//日期选择
- (IBAction)Date:(id)sender {

    DateViewController *d = [[DateViewController alloc]init];
    
    
    d.block = ^void (NSString *string1, NSString *string2){
        
        self.CheckLabel.text = string1;
        self.DepartureLabel.text = string2;
        self.Commonlabel.text = [NSString stringWithFormat:@"%ld晚",[self getDifferenceByDate:string1 Date1:string2]];
        
        self.Common =[NSString stringWithFormat:@"%ld",[self getDifferenceByDate:string1 Date1:string2]];
        
        NSLog(@"%@ == %@",string1,string2);
        
    };
    
    [self setAnimatedWithTransition];
    [nav pushViewController:d animated:NO];

}



- (NSInteger)getDifferenceByDate:(NSString *)date Date1:(NSString *)date1 {
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];

    //设定时间格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [dateFormatter1 setDateFormat:@"yyyy-MM-dd"];

    NSDate *oldDate = [dateFormatter dateFromString:date];
    NSDate *oldDate1 = [dateFormatter1 dateFromString:date1];

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    unsigned int unitFlags = NSDayCalendarUnit;
    NSDateComponents *comps = [gregorian components:unitFlags fromDate:oldDate  toDate:oldDate1  options:0];
    return [comps day];
}




- (void)setAnimatedWithTransition{
    
    CATransition *animation = [CATransition animation];
    //动画时间
    animation.duration = 0.7f;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    //过渡效果
    animation.type = @"cube";
    //过渡方向
    animation.subtype = kCATransitionFromRight;
    [nav.view.layer addAnimation:animation forKey:nil];
    
}

-(void)date{
    
    NSDate * date = [NSDate date];//当前时间
    NSDate *lastDay = [NSDate dateWithTimeInterval:24*60*60 sinceDate:date];//明天
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd";
     self.CheckLabel.text = [formatter stringFromDate:date];
     self.DepartureLabel.text = [formatter stringFromDate:lastDay];

    
    
}

//酒店图片浏览
-(void)tapAvatarView{
    
    [self.imageArr removeAllObjects];
    for (int i = 1 ; i<=7; i++) {
     
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"酒店环境%d.jpg",i]];
        [self.imageArr addObject:image];

    }
    
    [XLPhotoBrowser showPhotoBrowserWithImages:self.imageArr currentImageIndex:0];

    
}

-(NSMutableArray *)imageArr{
    
    if (!_imageArr) {
        _imageArr = [[NSMutableArray alloc]init];
    }
    return _imageArr;
    
}




@end
